@extends('frontend/layouts/bootstrap')

@section('content')

<div>
    <span style="font-size: 31.5px;  line-height: 40px;  margin: 10px 0;  font-family: inherit;  font-weight: bold;  color: inherit;  text-rendering: optimizelegibility;  -webkit-margin-before: 0.83em;  -webkit-margin-after: 0.83em;  -webkit-margin-start: 0px;  -webkit-margin-end: 0px;"> Purchase car document status</span>
    {{ link_to_route('car_balance.main.document_car_list', 'Return to Purchase Car list', null, array('class' => 'btn btn-info', 'style' => 'float: right; margin: 10px 0;')) }}
</div>

<!--<h2> Purchase car document status</h2>-->

<!--<ul class="breadcrumb">
    <li>
        <a href="{{ route('home') }}"><i class="icon-home"></i> Dashboard</a>
        <span class="divider"><i class="icon-chevron-right"></i></span>
    </li>
    <li>
        <a href="{{ route('car_balance.main.document_car_list') }}">Purchase Car list</a>
        <span class="divider"><i class="icon-chevron-right"></i></span>
    </li>
    <li class="active">Document status</li>
    <li style="float: right; margin-top: -5px;"></li>

</ul>-->

{{ Form::open(array('route' => array('car_balance.main.car_set_status', $car->id), 'class' => 'form-horizontal set-status-form', 'files' => true)) }}

<table class="table table-bordered" style="margin-bottom: 10px;">
    <thead style="background-color: #f0f0f0;">
    <tr>
        <th title="Дугаар">#</th>
        <th title="Date">日付</th>
        <th title="Auction">オーク会場</th>
        <th title="Auction no">出品番号</th>
        <th title="Car model">車種</th>
        <th title="Car year">年式</th>
        <th title="Chassis number">車体番号</th>
        <th title="Shakensyo">車検証到着</th>
    </tr>
    </thead>
    <tr>
        <td >{{ $car->id }}</td>
        <td>{{ $car->purchase_date }}</td>
        <td>{{ $car->auction_name }}</td>
        <td>{{ $car->lot_no }}</td>
        <td>{{ $car->car_maker }} {{ $car->car_name }}</td>
        <td>{{ $car->car_year }}</td>
        <td>{{ $car->chasis_no; }}</td>
        <td>{{ $car->shakensyo_flag ? '<span class="badge badge-success"><i class="icon icon-ok"></i></span>' : '<span class="badge badge-important"><i class="icon icon-remove"></i></span>' }}</td>
    </tr>
</table>
<table class="table table-bordered" style="margin-bottom: 10px;">
    <tr>
        <th style="background-color: #f0f0f0;" title="Registration number">登録番号</th>
        <td{{ $errors->first('registration_number', ' class="control-group error"') }}>
        <input class="input-medium" placeholder="Registration number" title="Registration number" name="registration_number" id="registration_number" type="text" value="{{ $car->registration_number }}" {{ $car->number_plate_flag ? 'enabled':'disabled' }}>
        {{ $errors->first('registration_number', '<span class="help-inline">:message</span>') }}
        @if ($car->number_arrival_flag and $car->fax_export_erasure_to_auction )
        <span class="badge badge-success"><i class="icon icon-ok"></i></span>
        @else
        <input id="number_arrival_flag" placeholder="チェック" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" onclick="setNumberArrival(this.checked, {{ $car->id }})" name="number_arrival_flag" {{  $car->number_arrival_flag ? 'checked' : '' }}  {{ $car->number_plate_flag ? 'enabled':'disabled' }}/>
        @endif
        </td>
    </tr>
    <tr>
        <th style="background-color: #f0f0f0;" title="Burtgel solih">抹消日</th>
        <td{{ $errors->first('burtgel_solih', ' class="control-group error"') }}>
        <input id="burtgel_solih_cb" placeholder="今日" type="checkbox" class="input-small" style="margin-top: 10px; margin-right: 5px; float: left;" onclick="setToday('burtgel_solih')" name="burtgel_solih_cb" {{ $car->shakensyo_flag ? 'enabled':'disabled' }} /><label style="float: left; padding-right: 10px; padding-top: 5px;" for="burtgel_solih_cb">今日</label>
        <input class="datepicker input-medium" placeholder="Burtgel solih" title="Burtgel solih" name="burtgel_solih" id="burtgel_solih" type="text" value="{{ $car->burtgel_solih }}" {{ $car->shakensyo_flag ? 'enabled':'disabled' }}>
        {{ $errors->first('burtgel_solih', '<span class="help-inline">:message</span>') }}
        </td>
    </tr>
    <tr>
        <th style="background-color: #f0f0f0;" title="Send export erasure to transport company">届書送付日</th>
        <td{{ $errors->first('send_export_erasure_to_transport_company', ' class="control-group error"') }}>
        <input id="send_export_erasure_to_transport_company_cb" placeholder="今日" type="checkbox" class="input-small" style="margin-top: 10px; margin-right: 5px; float: left;" onclick="setToday('send_export_erasure_to_transport_company')" name="send_export_erasure_to_transport_company_cb" {{ $car->shakensyo_flag ? 'enabled':'disabled' }} /><label style="float: left; padding-right: 10px; padding-top: 5px;" for="send_export_erasure_to_transport_company_cb">今日</label>
        <input class="datepicker input-medium" placeholder="Send export erasure to transport company" title="Send export erasure to transport company" name="send_export_erasure_to_transport_company" id="send_export_erasure_to_transport_company" type="text" value="{{ $car->send_export_erasure_to_transport_company }}" {{ $car->shakensyo_flag ? 'enabled':'disabled' }}>
        {{ $errors->first('send_export_erasure_to_transport_company', '<span class="help-inline">:message</span>') }}
        </td>
    </tr>
    <tr>
        <th style="background-color: #f0f0f0;" title="Mail export erasure to nmc">届書Image</th>
        <td>
            <div class="fileupload fileupload-new" data-provides="fileupload">
                <div id="export_erasure_image" class="input-append">
                    <div class="uneditable-input span3">
                        @if ( $car->mail_export_erasure_to_nmc_upload_flag )
                        <a target="_blank" style="margin-left: 25px;" class="btn btn-success btn-mini" href="{{route('car_balance.main.display', array('type'=>'export_cert', 'file'=>$car->chasis_no.'.jpg'))}}" title="{{ $car->car_year }}-{{ $car->car_name }}-{{ $car->chasis_no; }}"><i class="icon-zoom-in icon-white"></i></a>
                        <span class="fileupload-preview"></span>
                        @else
                        <i class="icon-file fileupload-exists"></i>
                        <span class="fileupload-preview"></span>
                        @endif
                    </div>
                    <div>
                    <span class="btn btn-file">
                        <span class="fileupload-new">Select file</span>
                        <span class="fileupload-exists">Change</span>
                        <input name="export_erasure_image" type="file" />
                    </span>
                        <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
                    </div>
                </div>
            </div>
            <!--<div class="fileupload fileupload-new" data-provides="fileupload">
                <div id="export_erasure_image" class="fileupload-new thumbnail" style="width: 20px;">
                    @if ( $car->mail_export_erasure_to_nmc_upload_flag )
                    <a href="{{ $car->mail_export_erasure_to_nmc;}}" data-lightbox="image-1" title="{{ $car->car_year }}-{{ $car->car_name }}-{{ $car->chasis_no; }}"><img src="{{ $car->mail_export_erasure_to_nmc;}}"></a>
                    @else
                    <img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&text=no+image" />
                    @endif
                </div>
                <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 20px; max-height: 20px; line-height: 20px;"></div>
<!--                <div>-->
                    <!--<span class="btn btn-file">
                        <span class="fileupload-new">Select image</span>
                        <span class="fileupload-exists">Change</span>
                        <input name="export_erasure_image" type="file" {{ $car->shakensyo_flag ? 'enabled':'disabled' }} /></span>
                    <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
                <span class="fileupload-filename">
                    {{ $car->mail_export_erasure_to_nmc_upload_flag ? $car->chasis_no.'.jpg' : '' }}</span>-->
<!--                </div>-->
            </div>
        </td>
    </tr>
    <tr>
        <th style="background-color: #f0f0f0;" title="Fax export erasure to auction">FAX送付日</th>
        <td{{ $errors->first('fax_export_erasure_to_auction', ' class="control-group error"') }}>
        <input id="fax_export_erasure_to_auction_cb" placeholder="今日" type="checkbox" class="number_arrival input-small" style="margin-top: 10px; margin-right: 5px; float: left;" onclick="setToday('fax_export_erasure_to_auction')" name="fax_export_erasure_to_auction_cb" {{ $car->number_arrival_flag ? 'enabled' : 'disabled' }} /><label style="float: left; padding-right: 10px; padding-top: 5px;" for="fax_export_erasure_to_auction_cb">今日</label>
        <input class="number_arrival datepicker input-medium" placeholder="Fax export erasure to auction" title="Fax export erasure to auction" name="fax_export_erasure_to_auction" id="fax_export_erasure_to_auction" type="text" value="{{ $car->fax_export_erasure_to_auction }}" {{ $car->number_arrival_flag ? 'enabled' : 'disabled' }}>
        {{ $errors->first('fax_export_erasure_to_auction', '<span class="help-inline">:message</span>') }}
        </td>
    </tr>
    <tr>
        <th style="background-color: #f0f0f0;" title="Car tax cancel">自動車税解約</th>
        <td{{ $errors->first('car_tax_cancel', ' class="control-group error"') }} {{ $errors->first('car_tax_cancel_amount', ' class="control-group error"') }}>
        <input id="car_tax_cancel_cb" placeholder="今日" type="checkbox" class="number_arrival input-small" style="margin-top: 10px; margin-right: 5px; float: left;" onclick="setToday('car_tax_cancel')" name="car_tax_cancel_cb" {{ $car->number_arrival_flag ? 'enabled' : 'disabled' }} /><label style="float: left; padding-right: 10px; padding-top: 5px;" for="car_tax_cancel_cb">今日</label>
        <input class="number_arrival datepicker input-medium" placeholder="Car tax cancel date" title="Car tax cancel date" name="car_tax_cancel" id="car_tax_cancel" type="text" value="{{ $car->car_tax_cancel }}" {{ $car->number_arrival_flag ? 'enabled' : 'disabled' }} >
        {{ $errors->first('car_tax_cancel', '<span class="help-inline">:message</span>') }}
        <input class="number_arrival input-medium" placeholder="Car tax cancel amount" title="Car tax cancel amount" name="car_tax_cancel_amount" type="text" value="{{ $car->car_tax_cancel_amount }}" {{ $car->number_arrival_flag ? 'enabled' : 'disabled' }} >
        @if ($car->car_tax_amount)
        <input style="float: right;" type="button" class="btn btn-primary btn-medium active" value="自動車税： {{ ( $car->car_tax_amount == 0 ) ? $car->car_tax_amount : number_format($car->car_tax_amount, 0); }}"/>
<!--        <input class="input-medium" placeholder="Car tax amount" title="Car tax amount" name="car_tax_amount" type="text" value="{{ ( $car->car_tax_amount == 0 ) ? $car->car_tax_amount :  number_format($car->car_tax_amount, 0); }}" disabled="disabled">-->
        @endif
        {{ $errors->first('car_tax_cancel_amount', '<span class="help-inline">:message</span>') }}
        </td>
    </tr>

    <tr>
        <th style="background-color: #f0f0f0;" title="Car liability insurance cancel">自賠責保険解約</th>
        <td{{ $errors->first('car_liability_insurance_cancel', ' class="control-group error"') }} {{ $errors->first('insurance_refund', ' class="control-group error"') }}>
        <input id="car_liability_insurance_cancel_cb" placeholder="今日" type="checkbox" class="number_arrival input-small" style="margin-top: 10px; margin-right: 5px; float: left;" onclick="setToday('car_liability_insurance_cancel')" name="car_liability_insurance_cancel_cb" {{ $car->number_arrival_flag ? 'enabled' : 'disabled' }} /><label style="float: left; padding-right: 10px; padding-top: 5px;" for="car_liability_insurance_cancel_cb">今日</label>
        <input class="number_arrival datepicker input-medium" placeholder="Car liability insurance cancel" title="Car liability insurance cancel" name="car_liability_insurance_cancel" id="car_liability_insurance_cancel" type="text" value="{{ $car->car_liability_insurance_cancel }}" {{ $car->number_arrival_flag ? 'enabled' : 'disabled' }} >
        {{ $errors->first('car_liability_insurance_cancel', '<span class="help-inline">:message</span>') }}
        <input class="number_arrival input-medium" placeholder="Car liability insurance cancel amount" title="Car liability insurance cancel amount" name="car_liability_insurance_cancel_amount" type="text" value="{{ $car->car_liability_insurance_cancel_amount }}" {{ $car->number_arrival_flag ? 'enabled' : 'disabled' }} >
        {{ $errors->first('car_liability_insurance_cancel_amount', '<span class="help-inline">:message</span>') }}
        </td>
    </tr>
    <tr>
        <th style="background-color: #f0f0f0;" title="Recycle date">リサイクル</th>
        <td{{ $errors->first('recycle_application_date', ' class="control-group error"') }} {{ $errors->first('recycle', ' class="control-group error"') }} {{ $errors->first('returned_recycle', ' class="control-group error"') }}>
        <input id="recycle_cb" placeholder="今日" type="checkbox" class="input-small" style="margin-top: 10px; margin-right: 5px; float: left;" onclick="setToday('recycle_application_date')" name="recycle_cb" {{ $car->shakensyo_flag ? 'enabled':'disabled' }} /><label style="float: left; padding-right: 10px; padding-top: 5px;" for="recycle_cb">今日</label>
        <input class="datepicker input-medium" placeholder="Recycle application date" title="Recycle application date" name="recycle_application_date" id="recycle_application_date" type="text" value="{{ $car->recycle_application_date }}" {{ $car->shakensyo_flag ? 'enabled':'disabled' }} >
        {{ $errors->first('recycle_application_date', '<span class="help-inline">:message</span>') }}
        <input class="datepicker input-medium" placeholder="Recycle date" title="Recycle date" name="recycle" id="recycle" type="text" value="{{ $car->recycle }}" {{ $car->shakensyo_flag ? 'enabled':'disabled' }} >
        {{ $errors->first('recycle', '<span class="help-inline">:message</span>') }}
        <input class="input-medium" placeholder="Returned recycle" title="Returned recycle" name="returned_recycle" type="text" value="{{ $car->returned_recycle }}" {{ $car->shakensyo_flag ? 'enabled':'disabled' }} >
        <input  style="float: right;" type="button" class="btn btn-primary btn-medium active" value="Ｒ預託金： {{ ( $car->recycle_amount == 0 ) ? $car->recycle_amount :  number_format($car->recycle_amount, 0); }}"/>
<!--        <input style="float: right;" class="btn btn-info" placeholder="Recycle amount" title="Recycle amount" name="recycle_amount" type="text" value="Ｒ預託金 : {{ ( $car->recycle_amount == 0 ) ? $car->recycle_amount :  number_format($car->recycle_amount, 0); }}" disabled="disabled">-->
        {{ $errors->first('returned_recycle', '<span class="help-inline">:message</span>') }}
        </td>
    </tr>
    <tr>
        <th style="background-color: #f0f0f0;" title="Comment">コメント</th>
        <td{{ $errors->first('comment', ' class="control-group error"') }}>
        <input class="input-large" placeholder="Document comment" title="Document comment" name="document_comment" type="text" value="{{ $car->document_comment }}" {{ $car->shakensyo_flag ? 'enabled':'disabled' }} >
        {{ $errors->first('document_comment', '<span class="help-inline">:message</span>') }}
        </td>
    </tr>
</table>

<button type="reset" class="btn btn-large btn-default">Reset</button>
<button type="submit" class="btn btn-large btn-success"><i class="icon-plus icon-white"></i> Хадгалах</button>
{{ Form::token() }}
{{ Form::close() }}

@if ( $car->mail_export_erasure_to_nmc_upload_flag )
<iframe id="myframe" width="100%" height="600" src="{{route('car_balance.main.display', array('type'=>'export_cert', 'file'=>$car->chasis_no.'.jpg'))}}"></iframe>
@endif

<div id="addStatusModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Status oruulah</h3>
    </div>
    <div class="modal-body">
        <div class="row-fluid">
            {{ Form::open(array('route' => array('car_balance.main.car_set_status', $car->id), 'class' => 'form-horizontal set-status-form')) }}

            <div  class="control-group {{ $errors->first('purchase_date', ' error') }}">
                <label class="control-label" for="container_id">Status</label>
                <div class="controls">
                    <input type="text" name="status" class="datepicker" id="status"/>
                    <input type="hidden" name="field" id="field"/>
                </div>
            </div>
            {{ Form::token() }}
            {{ Form::close() }}
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
        <button class="btn btn-primary" id="set-status-submit" >Set</button>
    </div>
</div>
@stop

@section('pagestyles')
<link rel="stylesheet" type="text/css" href={{ asset('assets/bootstrap-fileupload/fileupload.css') }} />
<link rel="stylesheet" type="text/css" href={{ asset('assets/lightbox/lightbox.css') }} />
<link rel="stylesheet" type="text/css" href={{ asset('assets/bootstrap-datepicker/datepicker.css') }} />
@stop

@section('pagescripts')
<script type="text/javascript" src={{ asset('assets/bootstrap-fileupload/fileupload.js') }}></script>
<script type="text/javascript" src={{ asset('assets/lightbox/lightbox-2.6.min.js') }}></script>
<script type="text/javascript" src={{ asset('assets/bootstrap-datepicker/datepicker.js') }}></script>
<script type="text/javascript">
    $(function() {
        $( ".datepicker" ).datepicker({
            //startDate: "-3m",
            //endDate: "+3m",
            defaultDate: "+0d",
            format: "yyyy-mm-dd",
            autoclose: true
        });
    });
    function setToday(textBoxID) {
        var currentTime = new Date()
        var month = currentTime.getMonth() + 1
        var day = currentTime.getDate()
        var year = currentTime.getFullYear()
        console.log(year  + "-" + month + "-" + day);
        document.getElementById(textBoxID).value = year  + "-" + pad(month) + "-" + pad(day);
    }
    function pad(d) {
        return (d < 10) ? '0' + d.toString() : d.toString();
    }
    function setNumberArrival(bEnable, carId) {
        var request = $.ajax({
            url: "{{ route('car_balance.main.set_number_arrival') }}",
            type: "GET",
            data: { carId : carId, status: bEnable },
            dataType: "JSON"
        });

        request.done(function(result) {
            console.log(result.status);
        });

        if (bEnable) {
            $(".number_arrival").removeAttr("disabled", "disabled");
            $(".number_arrival").attr("enabled", "enabled");
        } else {
            $(".number_arrival").removeAttr("enabled", "enabled");
            $(".number_arrival").attr("disabled", "disabled");
        }
    }

    $("#registration_number").each(function(i){
        $(this).change(function () {
            //$("#number_arrival_flag").attr("checked", "true");
            //console.log($("#number_arrival_flag").val());
            //setNumberArrival(true, {{ $car->id }});
            //$(".number_arrival").removeAttr("disabled", "disabled");
           // $(".number_arrival").attr("enabled", "enabled");
        });
    });
    $("#burtgel_solih").each(function(i){
        $(this).change(function () {
            if ({{$car->number_plate_flag}} == 1 && $(".number_arrival").attr("enabled")) {
                document.getElementById("car_tax_cancel").value=document.getElementById("burtgel_solih").value;
            }
        });
    });
    $(document).ready(function() {
        if ({{$car->number_plate_flag}} == 1) {
            $('#registration_number').focus();
        }
        else {
            $('#burtgel_solih_cb').focus();
        }
    });
    $("#myframe").load(function() {
        $('#myframe').contents().find('img').attr('width', '100%');
    });
</script>
@stop